// 处理前端返回来的数据


const postData = (req) => {
    return new Promise((resolve) => {
        let postData = "";

        // 接受数据流，数据是一段一段传输的，然后拼接起来变成postdata
        req.on("data", chunk => {
            postData += chunk.toString();
        })

        // 接受完成之后变成JOSN格式返回到req.body
        req.on("end", () => {
            try {
                resolve(JSON.parse(postData));
            } catch (error) {
                resolve({});
            }
        })
    })
}
module.exports = postData;

